package com.yfp.device.factory;

import com.yfp.common.core.domain.R;
import com.yfp.device.api.AuthService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 文件服务降级处理
 */
@Component
public class AuthFallbackFactory implements FallbackFactory<AuthService> {
    private static final Logger log = LoggerFactory.getLogger(AuthFallbackFactory.class);

    @Override
    public AuthService create(Throwable throwable) {
        log.error("auth服务调用失败:{}", throwable.getMessage());
        return new AuthService() {
            @Override
            public R<Map<String, Object>> machineLogin(String machineSn, String base64MachinePwd) {
                return R.fail("设备登录失败:" + throwable.getMessage());
            }

            @Override
            public R<?> logout(String token) {
                return R.fail("设备登出失败:" + throwable.getMessage());
            }

            @Override
            public R<?> refresh(String token) {
                return R.fail("设备刷新token失败:" + throwable.getMessage());
            }
        };
    }
}
